#ifndef SUBWINDOW_HEADER_VIZMF_PROJECT
#define SUBWINDOW_HEADER_VIZMF_PROJECT

#include <QMdiSubWindow>
#include <QMdiArea>
#include <QCloseEvent>
#include "src/gui/qt/mainwindow.h"

class SubWindow : public QMdiSubWindow
{
  Q_OBJECT
public:
  SubWindow(QMdiArea::ViewMode mode, QWidget *parent = 0);
  void setWorkspace(const int id) { workspaceId = id; }
  int wspId() const { return workspaceId; }
  void setViewMode(QMdiArea::ViewMode mode)
  {
    switch(mode)
    {
    case QMdiArea::SubWindowView:
      if (onTop) setWindowFlags(windowFlags() ^ Qt::WindowStaysOnTopHint);
      onTopAction->setChecked(onTop);
      onTopAction->setDisabled(false);
      break;
    case QMdiArea::TabbedView:
      if (onTop) setWindowFlags(windowFlags() ^ Qt::WindowStaysOnTopHint);
      onTopAction->setChecked(false);
      onTopAction->setDisabled(true);
      break;
    }
  }
private:
  int workspaceId;
  bool onTop;
protected:
  void closeEvent (QCloseEvent * closeEvent);
  void hideEvent (QHideEvent *hideEvent);
  void showEvent (QShowEvent *showEvent);
signals:
  void closed(int workspace);
  void visibilityChanged(bool flag);
  void savingRequested(int);
private:
  QAction* closeAction;
  QAction* onTopAction;
  QAction* separatorAction;
private slots:
  void setOnTop()
  {
    onTop = !onTop;
    setWindowFlags(windowFlags() ^ Qt::WindowStaysOnTopHint);
  }
};

#endif // SUBWINDOW_HEADER_VIZMF_PROJECT
